package com.oazon.common.util;

import java.util.ArrayList;
import java.util.List;

import com.moco.launcher.R;
import com.oazon.moco.bean.BatteryBean;

import android.content.Intent;
import android.content.res.Resources;
import android.os.BatteryManager;

public class BatteryUtil {
	
	private static List<BatteryBean> batteryBeans = new ArrayList<BatteryBean>();
	static{
		batteryBeans.add(new BatteryBean(4, 100));
	}
	
	public static int batteryProcess(int percent) {
		Integer[] newBattery = new Integer[] {//
		0, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10//
				, 12, 12, 13, 14, 14, 16, 17, 19, 19, 20//
				, 21, 23, 23, 24, 25, 26, 27, 28, 29, 30//
				, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33//
				, 34, 34, 34, 35, 35, 35, 36, 36, 37, 37//
				, 38, 39, 39, 40, 41, 42, 42, 42, 43, 43//
				, 44, 45, 46, 47, 48, 48, 49, 49, 50, 50//
				, 51, 53, 57, 59, 61, 63, 65, 67, 70, 72//
				, 74, 76, 77, 80, 81, 83, 84, 87, 89, 90//
				, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 //
		};

		return newBattery[percent];
	}
	
	public static boolean isBatteryPresent(Intent batteryChangedIntent) {
		return batteryChangedIntent.getBooleanExtra(
				BatteryManager.EXTRA_PRESENT, true);
	}

	public static String getBatteryPercentage(Intent batteryChangedIntent) {
		int level = batteryChangedIntent.getIntExtra(
				BatteryManager.EXTRA_LEVEL, 0);
		int scale = batteryChangedIntent.getIntExtra(
				BatteryManager.EXTRA_SCALE, 100);
		return String.valueOf(level * 100 / scale) + "%";
	}

	public static String getBatteryStatus(Resources res,
			Intent batteryChangedIntent) {
		final Intent intent = batteryChangedIntent;

		int plugType = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
		int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
				BatteryManager.BATTERY_STATUS_UNKNOWN);
		String statusString;
		if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
			statusString = res.getString(R.string.battery_info_status_charging);
			if (plugType > 0) {
				int resId;
				if (plugType == BatteryManager.BATTERY_PLUGGED_AC) {
					resId = R.string.battery_info_status_charging_ac;
				} else if (plugType == BatteryManager.BATTERY_PLUGGED_USB) {
					resId = R.string.battery_info_status_charging_usb;
				} else {
					resId = R.string.battery_info_status_charging_wireless;
				}
				statusString = statusString + " " + res.getString(resId);
			}
		} else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
			statusString = res
					.getString(R.string.battery_info_status_discharging);
		} else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
			statusString = res
					.getString(R.string.battery_info_status_not_charging);
		} else if (status == BatteryManager.BATTERY_STATUS_FULL) {
			statusString = res.getString(R.string.battery_info_status_full);
		} else {
			statusString = res.getString(R.string.battery_info_status_unknown);
		}

		return statusString;
	}
}
